package br.com.arken.spring.core.service;

import java.io.Serializable;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.transaction.annotation.Transactional;

public abstract class AbstractService<E, ID extends Serializable, R extends JpaRepository<E, ID>> {

	@Autowired
	protected R repository;

	@Transactional
	public E save(E entity) {
		this.repository.saveAndFlush(entity);
		return entity;
	}

	@Transactional
	public void delete(ID id) {
		this.repository.delete(id);
	}

	@Transactional(readOnly = true)
	public List<E> findAll() {
		return this.repository.findAll();
	}

	@Transactional(readOnly = true)
	public E findOne(ID id) {
		return this.repository.findOne(id);
	}

}
